package com.estate.utils.json;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class JSONItem{
	
	private List<Pair> fields;
	public JSONItem(){
		fields=new ArrayList<Pair>();
	}
	public void put(String key,String value){
		Pair p=new Pair();
		p.key=key;
		p.value=value;
		fields.add(p);
	}
	public String toJSON(){
		//{"appeId":"1","survId":"1","location":"","surveyDate":"2008-03-14",
		//"surveyTime":"12:19:47","inputUserId":"1","inputTime":"2008-03-14 12:21:51",
		//"modifyTime":"0000-00-00 00:00:00"},
		if(fields==null||fields.size()==0){
			return "{}";
		}
		StringBuilder sb=new StringBuilder();
		sb.append("{");
		int last=fields.size()-1;
		for(int i=0;i<last;i++){
			sb.append("'"+fields.get(i).key+"':'"
					+fields.get(i).value+"',");
		}
		sb.append("'"+fields.get(last).key+"':'"
				+fields.get(last).value+"'");
		sb.append("}");
		return sb.toString();
	}
	class Pair{
		public String key;
		public String value;
	}
}